package com.ryujung.dfs_backtracking;

import java.util.ArrayDeque;
import java.util.ArrayList;
import java.util.Deque;
import java.util.List;

class Solution78 {
    public List<List<Integer>> subsets(int[] nums) {
        List<List<Integer>> res = new ArrayList<>();
        Deque<Integer> stk = new ArrayDeque<>();
        dfs(nums, 0, stk, res);
        return res;
    }

    private void dfs(int[] nums, int index, Deque<Integer> stk, List<List<Integer>> res) {
        // 结束条件
        res.add(new ArrayList<>(stk));
        for (int i = index; i < nums.length; i++) {
            stk.addLast(nums[i]);
            dfs(nums, i + 1, stk, res);
            stk.removeLast();
        }
    }

    public static void main(String[] args) {
        Solution78 s = new Solution78();
        System.out.println(s.subsets(new int[]{1, 2, 3}));
    }
}